<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        tr {
            display: flex;
            justify-content: space-around;
        }

        td {
            width: 100px;
            height: 80px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            border: 1px solid rgb(174, 173, 173);
        }

        input {
            width: 50px;
            display: none;
        }

        .active {
            display: block;
        }
    </style>
</head>

<body>
    <table>
        <tr>
            <td><span>test1</span><input type="text" class="active"></td>
            <td><span>test2</span> <input type="text"></td>
        </tr>
        <tr>
            <td><span>test2</span><input type="text"></td>
            <td><span>test2</span><input type="text"></td>
        </tr>
        <tr>
            <td><span>test2</span><input type="text"></td>
            <td><span>test2</span><input type="text"></td>
        </tr>
        <tr>
            <td><span>test2</span><input type="text"></td>
            <td><span>test2</span><input type="text"></td>
        </tr>
    </table>
    <script>
        var uls = document.getElementsByTagName('td')
        var input = document.getElementsByTagName('input')
        console.log(uls);

        for (var i = 0; i < uls.length; i++) {
            
            uls[i].onclick = function () {
                for (var k = 0; k < uls.length; k++) {
                    input[k].className = ''
                    uls[k].style.color = 'black'
                }
                this.style.color = 'red'
                this.lastElementChild.className = 'active'

            }
                   
            input[i].onblur = function(){
                    this.parentNode.firstElementChild.innerHTML= this.value
                    this.className=''
                }



        }



    </script>
</body>

</html>